import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    songId: 1, // 当前歌曲id
    songIds: [], // 当前播放列表中所有歌曲id
    musicList: [], // 当前播放列表中所有歌曲信息数据
    showPlayMusic: false, // 是否出现播放音乐界面
    showPageLogin: false, // 是否出现登陆界面
    userInfo: JSON.parse(localStorage.getItem('user-info') || JSON.stringify({
      name: '',
      uid: 0,
      vipType: 11,
      token: '',
      backgroundUrl: '',
      avatarUrl: '',
      signature: '',
      cookie: ''
    }))
  },
  mutations: {
    storageSongId(state, {id, ids, musicArr}) {
      state.songId = id;
      if (ids) {
        state.songIds = ids;
      }
      if (musicArr) {
        state.musicList = musicArr;
      }
    },
    showSongPlay(state, bool) {
      state.showPlayMusic = bool;
    },
    showLoginPage(state, bool) {
      state.showPageLogin = bool;
    },
    setUserInfo(state, data) {
      localStorage.setItem('user-info', JSON.stringify(data));
      state.userInfo = data;
    },
  },
  actions: {},
  modules: {}
});
